package com.baibei.order.bill.querymoney;

import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.baibei.model.PaymentRecordInfo;
import com.baibei.order.R;
import com.baibei.order.R2;
import com.baibei.order.bill.sticky_header.StickyDateAdapter;
import com.baibei.order.bill.viewtype.ViewType;
import com.blankj.utilcode.utils.TimeUtils;
import com.rae.swift.Rx;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 收支记录
 * Created by shenminjie on 2017/8/9.
 * mail:shenminjie@100bei.com
 */

class PaymentPickUpRecordAdapter extends StickyDateAdapter<PaymentRecordInfo> {


    @Override
    public RecyclerView.ViewHolder getItemViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ViewType.ITEM.ordinal()) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_payment_pickup_record, parent, false);
            return new ItemViewHolder(view);
        }
        return null;
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ItemViewHolder) {
            PaymentRecordInfo info = mRecordObjs.get(position);
            ItemViewHolder viewHolder = (ItemViewHolder) holder;
            viewHolder.tvName.setText(info.getProDesc());
            viewHolder.tvDate.setText(TimeUtils.millis2String(info.getAddTime(), "MM-dd HH:mm:ss"));
            int colorResource;
            StringBuilder money = new StringBuilder();
            if (info.getMoney() > 0) {
                colorResource = R.color.buyColor;
                money.append("+");
            } else {
                colorResource = R.color.textPrimary;
            }
            money.append(String.valueOf(Rx.formatPrice(info.getMoney())));
            viewHolder.tvAmount.setText(money);
            viewHolder.tvAmount.setTextColor(ResourcesCompat.getColor(viewHolder.itemView.getResources(), colorResource, null));
            viewHolder.tvSerialNumber.setText(String.format(holder.itemView.getContext().getString(R.string.string_order_num), info.getOrderNumber()));
            viewHolder.tvBalance.setText(String.format(holder.itemView.getContext().getString(R.string.figure_balance), Rx.formatPrice(info.getBalance())));
            viewHolder.tvType.setText(info.getOrderTypeStr());
        }
    }

    static class ItemViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.tv_name)
        TextView tvName;
        @BindView(R2.id.tv_amount)
        TextView tvAmount;
        @BindView(R2.id.tv_date)
        TextView tvDate;
        @BindView(R2.id.tv_type)
        TextView tvType;
        @BindView(R2.id.tv_balance)
        TextView tvBalance;
        @BindView(R2.id.tv_serial_number)
        TextView tvSerialNumber;

        ItemViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
